// QtCore
#include <QtCore/QTextCodec>
#include <QtCore/QTextStream>
#include <QtCore/QCoreApplication>
// Локальные
#include "settings.h"
#include "conicsolver.h"
#include "abstractsolver.h"
#include "cylindricalsolver.h"
#include "cylindricalconicsolver.h"

//================================================================================================================================
//================================================================================================================================
int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    app.setOrganizationName("BlackSoft"); // :)
    app.setApplicationName("Bridgman");
    app.setApplicationVersion("1.1.0");

    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));

    //****************************************************************************************************************************
    //****************************************************************************************************************************
    QTextStream cout(stdout);
    QTextStream cin(stdin);
    cout.setCodec(QTextCodec::codecForName("IBM866"));
    cin.setCodec(QTextCodec::codecForName("IBM866"));

    Settings::init();
    Settings::instance()->updateSettings();

    int solver_type = Settings::instance()->setting("Solver/SolverType").toInt();

    if(solver_type == -1)
    {
        cout << QObject::tr("Список доступных решателей:") << endl;
        cout << QObject::tr("0 - Цилиндрический тигель") << endl;
        cout << QObject::tr("1 - Конический тигель") << endl;
        cout << QObject::tr("2 - Цилиндрически-конический тигель") << endl;
        cout << QObject::tr("Выберите нужный решатель") << endl;
        cin >> solver_type;
    }

    AbstractSolver* solver;
    switch(solver_type)
    {
    case 0:
        solver = new CylindricalSolver();
        break;
    case 1:
        solver = new ConicSolver();
        break;
    case 2:
        solver = new CylindricalConicSolver();
        break;
    default:
        qFatal("Unknown or unsupported solver type");
    }

    if(Settings::instance()->setting("Solver/Solver").toBool())
        solver->solve();
    if(Settings::instance()->setting("Postproc/Postproc").toBool())
        solver->postproc();

    cout << QObject::tr("Работа программы успешно завершена!") << endl;
    Settings::deinit();
    return 0;
}
